package formulation.controllers;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import db.vector.Vector;
import db.vector.VectorService;

public class VectorController extends MultiActionController
{
    private VectorService vectorService;

    public void setVectorService(VectorService vectorService) {
        this.vectorService = vectorService;
    }
    
    public ModelAndView list(HttpServletRequest request,
            HttpServletResponse response)
    {
        return new ModelAndView("vector/vector", "vectors", vectorService.list());
    }
    
    public void findClassificationByVectorId(HttpServletRequest request,
            HttpServletResponse response) throws IOException
    {
        Long id = Long.parseLong(request.getParameter("id"));
        Vector vector = vectorService.find(id);
        PrintWriter out = response.getWriter();
        out.print(vector.getClassification().getName());
    }
}
